<template>
	<div>
		<span v-html="status"></span>
		<span>{{ production }}</span>
	</div>
</template>
<script>
	import { getProduction } from '@/api/production'
	import { getStock2 } from '@/api/stock'
	export default {
		data() {
			return { production: null, status: '' }
		},
		beforeMount() {
			getProduction(this.params.value)
				.then(response => {
					if (response.Result === 0) {
						this.production = response.Data.Name
						getStock2(response.Data.Code)
							.then(response => {
								let data = JSON.parse(response.data)
								if (data.IsSuccess) {
									let msg = JSON.parse(data.Message)[0]
									if (msg.ExpectQty > 10) {
										this.status =
											'<font color="green">[库存:' + msg.ExpectQty + ']</font>'
									} else if (msg.ExpectQty <= 10 && msg.ExpectQty > 0) {
										this.status = '<font color="orange">[库存:' + msg.ExpectQty + ']</font>'
									} else if (msg.ExpectQty == 0) {
										this.status = '<font color="red">[无货]</font>'
									}
								} else {
									this.status = '<font color="red">[未知]</font>'
								}
							})
							.catch(error => { })
					}
				})
				.catch(error => {
					this.production = '未知错误'
				})
		}
	}
</script>
